package org.lcc.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.lcc.model.entity.Exam;
import org.lcc.model.entity.ExamRecord;
import java.util.List;
import java.util.Map;

@Mapper
public interface ExamMapper extends BaseMapper<Exam> {
    // 获取已结束的考试列表（分页）
    List<Exam> getFinishedExams(@Param("schoolNumber") String schoolNumber);
    
    /**
     * 获取考试详情
     * @param examId 考试ID
     * @return 考试详情
     */

    Exam getExamById(@Param("examId") Integer examId);
    
    // 获取考试的学生记录
    List<ExamRecord> getExamRecords(@Param("examId") Integer examId);
    
    /**
     * 获取考试的学生数量
     * @param examId 考试ID
     * @return 学生数量
     */

    Integer getStudentCount(@Param("examId") Integer examId);
    
    /**
     * 获取考试的平均分
     * @param examId 考试ID
     * @return 平均分
     */

    Double getAverageScore(@Param("examId") Integer examId);
    
    /**
     * 获取考试的最高分
     * @param examId 考试ID
     * @return 最高分
     */

    Integer getHighestScore(@Param("examId") Integer examId);
    
    /**
     * 获取考试的最低分
     * @param examId 考试ID
     * @return 最低分
     */

    Integer getLowestScore(@Param("examId") Integer examId);
    
    /**
     * 获取符合条件的学生列表（成绩大于等于及格分数线）
     * @param examId 考试ID
     * @param passThreshold 及格分数线
     * @return 符合条件的学生列表
     */
    @Select("SELECT er.student_id AS studentId, u.real_name AS studentName, er.total_score AS score " +
            "FROM exam_record er " +
            "JOIN user u ON er.student_id = u.school_number " +
            "WHERE er.exam_id = #{examId} AND er.status = '已批改' AND er.total_score >= #{passThreshold} " +
            "ORDER BY er.total_score DESC")
    List<Map<String, Object>> getQualifiedStudents(@Param("examId") Integer examId, @Param("passThreshold") Integer passThreshold);
} 